//
//  RewardListTableView.m
//  Base_App
//
//  Created by Yutian Duan on 2019/6/3.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "RewardListTableView.h"
#import "RewardListCell.h"

@implementation RewardListTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
  self = [super initWithFrame:frame style:style];
  if (self) {
    self.rowHeight = (ScreenWidth - 40) * ITEMPRO + 20;
  }
  return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  if (section == 0) {
    return _firstArr.count;
  } else {
    return _secondArr.count;
  }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  return 50;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  
  UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)];
  headView.backgroundColor = HEXCOLOR(0xf7f8fc);
  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, ScreenWidth - 100, 50)];
  label.textColor = DEF_BLACK;
  label.font = [UIFont systemFontOfSize:20.f];
  label.textAlignment = NSTextAlignmentLeft;
  [headView addSubview:label];
  
  if (section == 0) {
    label.text = YTLocalizedString(@"可使用优惠");
  } else {
    label.text = YTLocalizedString(@"已失效优惠");
  }
  return headView;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  RewardListCell *cell = nil;
  
  if (indexPath.section == 0) {
    static NSString *identifyOne = @"identifyOne";
    cell = [tableView dequeueReusableCellWithIdentifier:identifyOne];
    if (!cell) {
      cell = [[RewardListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifyOne];
    }
    cell.model = _firstArr[indexPath.row];
  } else {
    static NSString *identifyTwo = @"identifyTwo";

    cell = [tableView dequeueReusableCellWithIdentifier:identifyTwo];
    if (!cell) {
      cell = [[RewardListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifyTwo];
    }
    cell.model = _secondArr[indexPath.row];
  }
  
  
  return cell;
}


@end
